package it.polimi.traveldream.entity;

import it.polimi.traveldream.dto.UserDTO;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 * Entity implementation class for Entity: Customer
 * 
 */
@Entity
@DiscriminatorValue("customer")
@NamedQuery(name = Customer.FIND_USER, query = "SELECT c FROM Customer c WHERE c.email = :email")
public class Customer extends User implements Serializable {
	private static final long serialVersionUID = 1L;

	public static final String FIND_USER = "Customer.findUser";

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
	private List<CartPackage> cart;

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
	private List<GiftlistElement> giftlist;

	public Customer() {
		super();
	}

	public Customer(UserDTO user) {
		super(user);
	}

	public List<CartPackage> getCart() {
		return this.cart;
	}

	public void setCart(List<CartPackage> cart) {
		this.cart = cart;
	}

	public boolean addCartPackage(CartPackage cartPackage) {
		cartPackage.setUser(this);
		return this.getCart().add(cartPackage);
	}

	public boolean removeCartPackage(CartPackage cartPackage) {
		return this.getCart().remove(cartPackage);
	}

	public List<GiftlistElement> getGiftlist() {
		return this.giftlist;
	}

	public void setGiftlist(List<GiftlistElement> giftlist) {
		this.giftlist = giftlist;
	}

	public boolean addGiftlistElement(GiftlistElement giftlistElement) {
		giftlistElement.setUser(this);
		return this.getGiftlist().add(giftlistElement);
	}

	public boolean removeGiftlistElement(GiftlistElement giftlistElement) {
		return this.getCart().remove(giftlistElement);
	}

}
